#!/usr/bin/env python
#coding:utf-8

import sys

################################################################################
#GUI部分
################################################################################
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class mywindow(QDialog):
    '''
    desc:主窗口
    '''
    def __init__(self):
        '''
        desc:初始化
        '''
        super(QDialog, self).__init__()

        self.createMenu()
        self.createGridGroupBox()

        #按钮
        buttonbox = QDialogButtonBox(QDialogButtonBox.Close)
        buttonbox.clicked.connect(self.close)

        #显示结果的列表框部件
        self.listwidget=QListWidget()
        self.listwidget.addItem('a')
        self.listwidget.addItem('b')

        #主界面布局
        mainlayout = QVBoxLayout()
        mainlayout.setMenuBar(self.menuBar)
        mainlayout.addWidget(self.gridGroupBox)
        mainlayout.addWidget(self.listwidget)
        mainlayout.addWidget(buttonbox)
        self.setLayout(mainlayout)

        #连接信号和槽
        self.connect(self.pushbutton_search, SIGNAL('clicked()'), self.search)

    def createMenu(self):
        '''
        desc:创建菜单
        '''
        #菜单栏
        self.menuBar = QMenuBar()
        #菜单
        self.fileMenu = QMenu('&File', self)
        self.exitAction = self.fileMenu.addAction('E&xit')
        self.menuBar.addMenu(self.fileMenu)
        #连接信号和槽
        self.exitAction.triggered.connect(self.accept)


    def createGridGroupBox(self):
        '''
        desc:创建网格分组框
        '''
        self.gridGroupBox = QGroupBox(u'输入信息：')
        #布局部件
        layout = QGridLayout()

        #获得用户信息的部件
        label1=QLabel(u'输入需要搜索的字符串:')
        self.lineedit_searchstr=QLineEdit()
        self.checkbox_casesensitive=QCheckBox(u'区分大小写')
        self.pushbutton_search=QPushButton(u'搜索')

        #布局部件
        layout.addWidget(label1, 0, 0)
        layout.addWidget(self.lineedit_searchstr, 0, 1)
        layout.addWidget(self.checkbox_casesensitive, 0, 2)
        layout.addWidget(self.pushbutton_search, 0, 3)
        layout.setColumnStretch(1,10)
        self.gridGroupBox.setLayout(layout)


    def getuserinput(self):
        '''
        desc:获取用户输入参数信息
        '''
        self.userinputargs={}
        self.userinputargs['searchstr']=str(self.lineedit_searchstr.text())
        self.userinputargs['casesensitive']=self.checkbox_casesensitive.isChecked()
    def showuserinput(self):
        '''
        desc:调试用，显示获取到的用户输入信息
        '''
        print '='*50
        for k, v in self.userinputargs.items():
            print k, '=', v

    def search(self):
        '''
        desc:根据用户输入信息搜索，并显示结果到文本框部件中
        '''
        self.getuserinput()
        self.showuserinput()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = mywindow()
    window.show()
    sys.exit(app.exec_())
